package com.example.finaltool.mapper;

import com.example.finaltool.model.RangeQuery;
import com.example.finaltool.model.db.info.Range;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author dengbw
 * @date 2021/8/16 1:39 下午
 */
@Mapper
public interface InfoMapper {

    @Select("SELECT ic.id as consult_id, #{type} as info_type, scv.sub_tenant_id as release_range, scv.NAME as range_name, scv.tenant_id as tenant_id, scv.sub_tenant_id as sub_tenant_id " +
            "FROM ${table} ic, sys_corp_village scv " +
            "WHERE ic.tenant_id = scv.tenant_id AND ic.sub_tenant_id = scv.sub_tenant_id " +
            "AND scv.tenant_id = #{corpId}")
    List<RangeQuery> getRangeQuery(String table, String type, String corpId);

    @Select("SELECT ic.id as consult_id, #{type} as info_type, scv.sub_tenant_id as release_range, scv.NAME as range_name, scv.tenant_id as tenant_id, scv.sub_tenant_id as sub_tenant_id " +
            "FROM ${table} ic, sys_corp_village scv " +
            "WHERE ic.tenant_id = scv.tenant_id AND ic.sub_tenant_id = scv.sub_tenant_id " +
            "AND scv.tenant_id = #{corpId}")
    List<Range> getRange(String table, String type, String corpId);

    @Update("UPDATE info_consulting_range SET sub_tenant_id = #{subId} WHERE tenant_id = #{corpId} AND range_name = #{name}")
    void fillSub(String corpId, String name, Long subId);
}
